package com.taotao.cart.controller;

import com.taotao.cart.domain.CarReq;
import com.taotao.cart.domain.response.CartResponse;
import com.taotao.cart.service.CartService;
import com.taotao.common.core.domain.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cartItem")
public class CartController {
    @Resource
    private CartService cartService;

    /**
     * 获取当前用户购物车列表
     */
    @GetMapping("/cartList")
    public Result<List<CartResponse>> cartList() {
        List<CartResponse> cartResponses= cartService.cartList();
        return Result.success(cartResponses);
    }

    /**
     * 添加购物车
     */
    @GetMapping("/addCart/{skuId}/{quantity}")
    public Result addToCart(@PathVariable("skuId") Long skuId, @PathVariable Integer quantity) {
        cartService.addToCart(skuId, quantity);
        return Result.success();
    }

    /**
     * 删除购物车
     */
    @PostMapping("/deleteCart")
    public Result deleteCart(@RequestBody List<Long> skuIds) {
        cartService.deleteCart(skuIds);
        return Result.success();
    }

    /**
     * 订单信息
     */
    @PostMapping("/orderInfo")
    public Result<List<CartResponse>> orderInfo(@RequestBody CarReq carReq) {
        List<Long> skuId = carReq.getSkuIds();
        Integer userId = carReq.getUserId();
        List<CartResponse> cartResponses = cartService.selectCartOrderInfoBySkuId(skuId,userId);
        return Result.success(cartResponses);
    }


}
